<script language="JavaScript">
	function useExisting() {
		bUseExisting = document.form_appconfig_setup.bUseExisting.checked;
		if (bUseExisting) {
			elfHide('elf_appconfig_setup_root_listtop');
			elfHide('elf_appconfig_setup_root_user');
			elfHide('elf_appconfig_setup_root_pass');
			elfHide('elf_appconfig_setup_data_passagain');
		}
		else {
			elfShow('elf_appconfig_setup_root_listtop');
			elfShow('elf_appconfig_setup_root_user');
			elfShow('elf_appconfig_setup_root_pass');
			elfShow('elf_appconfig_setup_data_passagain');
		}
	}
</script>
<form action="index.php" method="post" name="form_appconfig_setup">
<input type="hidden" name="sAction" value="appconfig-setup">
<input type="hidden" name="sView" value="appconfig-setup">
<table class="boxborder" cellspacing="0">
	<tr>
		<td class="boxhandle" colspan="2"><?= msg('Setup') ?></td>
	</tr>
<?php
if (DATABASE_OK === true) {
	?>
	<tr>
		<td class="boxbody center" colspan"2">
			<?= msg('The application has already been set up.') ?><br />
			<?= msg('Go to "Upgrade" if you intend to upgrade the application.') ?><br />
		</td>
	</tr>
	<?php
}
else if (is_writable('include/dblogin.inc.php')) {
	?>
	<tr>
		<td class="listtop" colspan="2"><?= msg('Instructions') ?></td>
	</tr>
	<tr>
		<td class="boxbody small" colspan="2" style="width: 350px;">
	<?
	print msg('MiJob requires a MySQL database to function.').'<br /><br />';
	print msg('If you already have write-access to a database you only need to fill out "MiJob connection" here below and check "Use existing database". However, if you need to create a new database for MiJob, you first need root-access to the MySQL database. If you don\'t have root-access to the MySQL database but still need to create a new one, please contact the MySQL server administrator.').'<br /><br />';
	print msg('Under "MiJob access" you should put in the MiJob user. That user automatically gets the privileges required to create additional users once installation is complete.').'<br /><br />';
	print msg('IMPORTANT: If an existing database is used, all information in it will be destroyed before installation.').'<br /><br />';
	?>
		</td>
	</tr>
	<tr>
		<td class="listtop" colspan="2"><?php print msg('MySQL access') ?></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('MySQL server') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sDataHost" value="localhost"></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('MySQL user') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sDataUser" value="<?php print (@$_REQUEST['sDataUser'] ? $_REQUEST['sDataUser'] : 'mijob') ?>"></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('MySQL password') ?>:</td>
		<td class="fieldvalue"><input type="password" name="sDataPass"></td>
	</tr>
	<tr id="elf_appconfig_setup_data_passagain">
		<td class="fieldname"><?php print msg('MySQL password confirmation') ?>:</td>
		<td class="fieldvalue"><input type="password" name="sDataPassAgain"></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('MySQL database') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sDataBase" value="<?php print (@$_REQUEST['sDataBase'] ? $_REQUEST['sDataBase'] : 'mijob') ?>">
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Use existing database') ?>:</td>
		<td class="fieldvalue">
			<input type="checkbox" name="bUseExisting" value="1" onClick="useExisting();" <?php print (@$_REQUEST['bUseExisting'] ? 'checked' : '') ?>>
		</td>
	</tr>
	<tr id="elf_appconfig_setup_root_listtop">
		<td class="listtop" colspan="2"><?php print msg('MySQL root access') ?></td>
	</tr>
	<tr id="elf_appconfig_setup_root_user">
		<td class="fieldname"><?php print msg('MySQL root user') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sRootUser" value="root"></td>
	</tr>
	<tr id="elf_appconfig_setup_root_pass">
		<td class="fieldname"><?php print msg('MySQL root password') ?>:</td>
		<td class="fieldvalue"><input type="password" name="sRootPass"></td>
	</tr>
	<tr>
		<td class="listtop" colspan="2"><?php print msg('MiJob access') ?></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Username') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sUser" value="<?php @print $_REQUEST['sUser'] ?>"></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Password') ?>:</td>
		<td class="fieldvalue"><input type="password" name="sPass"></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Password confirmation') ?>:</td>
		<td class="fieldvalue"><input type="password" name="sPassAgain"></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Full name') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sFullname" value="<?php print @$_REQUEST['sFullname'] ?>"></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Email') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sEmail" value="<?php print @$_REQUEST['sEmail'] ?>"></td>
	</tr>
	<tr>
		<td class="boxbody center" colspan="2">
			<input type="submit" value="<?php print msg('Install') ?>">
		</td>
	</tr>
	<?php
}
else {
	?>
	<tr>
		<td class="boxbody center" colspan="2">
			<span class="error">
			<?php print msg('ERROR: The file \'include/dblogin.inc.cfm\' must be writable before installation. Please make it writable and try again.'); ?>
			</span><br>
		</td>
	</tr>
	<tr>
		<td class="boxbody center" colspan="2">
			<input type="button" name="bTryAgain" value="<?php print msg('Try again') ?>" onClick="location.href = 'index.php?sView=appconfig-setup';">
			<script language="JavaScript">
				document.form_appconfig_setup.bTryAgain.focus();
			</script>
		</td>
	</tr>
	<?php
}
?>
</table>
</form>
<script language="JavaScript">
	document.form_appconfig_setup.sDataPass.focus();
	useExisting();
</script>
